package com.lovedice;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class Preferences extends PreferenceActivity {
	SharedPreferences prefs = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
		prefs = PreferenceManager.getDefaultSharedPreferences(this);
		
		Preference findPreference = findPreference("clearNames");
		
		findPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
			@Override
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				SharedPreferences.Editor editor = prefs.edit();
				editor.putString("partner_name_one", getResources().getString(R.string.partner_1));
				editor.putString("partner_name_two", getResources().getString(R.string.partner_2));
				editor.commit();
				Toast.makeText(preference.getContext(), getResources().getString(R.string.pref_clear_names_phrase), Toast.LENGTH_LONG).show();
				return false;
			}
		});
		
	}
}

